/**
 * 描述: 菜单配置表详情页
 *
 * @author guoqiao
 * @since 2021-05-28 16:23:56
 */
layui.define(['index', 'form', 'table', 'laypage', 'zmnApp', 'layedit'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;
    let zmnApp = layui.zmnApp;
    // 菜单类型
    let menuType = json.menu.menuType;

    form.render(null, "zmn-form");

    // 提交
    form.on('submit(zmn-form-submit)', function (obj) {
        var data = obj.field;
        var url = "/mcc/menu/modify/addEdit.action";

        $.ajax({
            async: false,
            type: "POST",
            url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success: function (result) {
                let message = result.status == zmnStatus.SUCCESS ? "操作成功！" : result.message;
                layer.msg(message);
                if (result.status == zmnStatus.SUCCESS && !zmnUtil.isNotZeroInteger(data.menuId)) {

                    zmnPage.direct(zmnApp.SYS_BASE_URL + "/mcc/menu/addEditView.action?menuId=" + result.data, 2000);
                } else if (json.status == zmnStatus.FAIL) {
                    jumpStop = true;
                }
                return;
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
        return false;
    });

    if (json.menu.menuType == 1) {
        //目录类型
        $("#menu_url").hide();
        $("#menu_permit_url").hide();
        $("#sys_id").hide();
    } else if (json.menu.menuType == 2) {
        // 菜单类型
        $("#menu_url").show();
        $("#menu_permit_url").show();
        $("#sys_id").show();
    }

    // 菜单类型控制输入框是否显示
    form.on('radio(select-menu-type)', function (obj) {

        if (obj.value == 1) {
            // 一级菜单 不显示
            $('#menu_url').hide();
            $('#menu_permit_url').hide();
            $("#sys_id").hide();
            menuType = 1;

        } else if (obj.value == 2) {
            // 二级菜单显示
            $('#menu_url').show();
            $('#menu_permit_url').show();
            $("#sys_id").show();
            menuType = 2;
        } else {
            //
        }
    });

    form.verify({
        isRequiredMenuUrl: function (value) {
            if (menuType === 2) {
                if (value === undefined || value == null || value === '') {
                    return "请输入菜单URL!";
                }
            }
        },
        isRequiredMenuPermitUrl: function (value) {
            if (menuType === 2) {
                if (value === undefined || value == null || value === '') {
                    return "请输入菜单权限URL!";
                }
            }
        },
        isRequiredSysId: function (value) {
            if (menuType === 2) {
                if (value === undefined || value == null || value === '') {
                    return "请选择所属系统!";
                }
            }
        }

    });

    // 取消
    $(document).on('click', '#cancel', function () {
        parent.layui.admin.events.closeThisTabs();
    });


    //对外暴露的接口
    exports('plat_menu_detail', {});
});
